package com.game.listener.dispatcher;

import java.util.ArrayList;
import java.util.List;

import com.game.listener.ShipListener;
import com.game.listener.event.ShipEvent;

public class ShipDispatcher {
	private static ShipDispatcher instance;
	private List<ShipListener> listeners;

	private ShipDispatcher() {
		this.listeners = new ArrayList<ShipListener>();
	}

	public synchronized static ShipDispatcher getInstance() {
		if(ShipDispatcher.instance == null) {
			ShipDispatcher.instance = new ShipDispatcher();
		}

		return ShipDispatcher.instance;
	}

	public void addShipListener(ShipListener listener) {
		this.listeners.add(listener);
	}

	public void removeShipListener(ShipListener listener) {
		this.listeners.remove(listener);
	}

	public void dispatchShipEvent(ShipEvent event) {
		for (ShipListener listener : this.listeners) {
			listener.moveAction(event);
		}
	}
}
